import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const HomeView = () => import('../views/HomeView.vue')
const VideoView = () => import('../views/VideoView.vue')
const VideoDetailView = () => import('../views/VideoDetailView.vue')

const routes = [
  {
    path: '',
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'home',
    component: HomeView,
    meta: {
      title: 'QQ音乐'
    }
  },
  {
    path: '/music',
    name: 'music',
    component: HomeView,
    meta: {
      title: '音乐'
    }
  },
  {
    path: '/video',
    name: 'video',
    component: VideoView,
    meta: {
      title: '视频'
    }
  },
  {
    path: '/video/detail',
    name: 'videoDetail',
    component: VideoDetailView,
    meta: {
      title: '视频详情'
    }
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  document.title = to.meta.title;
  next();
})

export default router
